package com.lenovo.manufacture.module;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import com.lenovo.manufacture.BaseActivity;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.annotation.Layout;
import com.lenovo.manufacture.fragment.Fragment11_1;
import com.lenovo.manufacture.fragment.Fragment11_2;

import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;

public class Module11 extends BaseActivity {

    List<Fragment> views;
    String[] title = {"车辆定制", "订单详情"};
    @BindView(R.id.tl_tab)
    TabLayout tlTab;
    @BindView(R.id.vp_pager)
    ViewPager vpPager;
    public Fragment11_2 fragment11_2;

    @Layout(value = R.layout.activity_module11,title = "车辆定制")
    protected void init() {
        getSupportActionBar().setElevation(0);
        views = new ArrayList<>();
        views.add(new Fragment11_1());
        fragment11_2 = new Fragment11_2();
        views.add(fragment11_2);
        vpPager.setAdapter(new OrderPagerAdapter(getSupportFragmentManager()));
        tlTab.setupWithViewPager(vpPager);
    }

    class OrderPagerAdapter extends FragmentPagerAdapter {

        public OrderPagerAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return views.size();
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return views.get(position);
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }
}